package com.hzt.agprosaleplatform.controller;

import com.hzt.agprosaleplatform.dto.RouteDTO;
import com.hzt.agprosaleplatform.service.LogisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.hzt.agprosaleplatform.common.Result;

@RestController
@RequestMapping("/apis/logistics")
public class LogisticsController {

    @Autowired
    private LogisticsService logisticsService;

    private static final Logger logger = LoggerFactory.getLogger(LogisticsController.class);

    @GetMapping("/route/{orderId}")
    public Result getRoute(@PathVariable Long orderId) {
        try {
            RouteDTO route = logisticsService.getRouteForOrder(orderId);
            return new Result<>(true, 200, "Success", route);
        } catch (Exception e) {
            logger.error("Error getting route for orderId: {}", orderId, e);
            return new Result<>(false, 500, e.getMessage());
        }
    }
}
